#!/bin/bash

server_url=127.0.0.1:8130
#token='authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVVUlEIjoiNzVkYzRjMmMtZDYwMy00NTU1LTgxZjgtOGJhOTc0M2U1NzEwIiwiSUQiOjEsIlVzZXJuYW1lIjoiYWRtaW4iLCJOaWNrTmFtZSI6Iui2hee6p-euoeeQhuWRmCIsIkF1dGhvcml0eUlkIjoiODg4IiwiQnVmZmVyVGltZSI6ODY0MDAsImV4cCI6MTY2NDA5OTQ5MCwiaXNzIjoibWFpbmZsdXguYXV0aCIsIm5iZiI6MTY2MzQ5MzY5MCwic3ViIjoiZGVmYXVsdCJ9.eWiMr4nipBkhXXvz6PU1mvJT8mdzxv9lf4a6M97dajQ'
#server_url=42.96.191.189:8130
#token='authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVVUlEIjoiNzVkYzRjMmMtZDYwMy00NTU1LTgxZjgtOGJhOTc0M2U1NzEwIiwiSUQiOjEsIlVzZXJuYW1lIjoiYWRtaW4iLCJOaWNrTmFtZSI6Iui2hee6p-euoeeQhuWRmCIsIkF1dGhvcml0eUlkIjoiODg4IiwiQnVmZmVyVGltZSI6ODY0MDAsImV4cCI6MTY2NDA5OTQ5MCwiaXNzIjoibWFpbmZsdXguYXV0aCIsIm5iZiI6MTY2MzQ5MzY5MCwic3ViIjoiZGVmYXVsdCJ9.eWiMr4nipBkhXXvz6PU1mvJT8mdzxv9lf4a6M97dajQ'
function login() 
{
	user=${1}
	pass=${2}
	#echo "$user and $pass login!"
	result=`curl -v "http://${server_url}/role/base/login" -H 'Accept: application/json, text/plain, */*'  -H 'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6' -H 'Content-Type: application/json' \
	  -H "${token}" \
	  --data-raw "{\"username\":\"${user}\",\"password\":\"${pass}\",\"captcha\":\"__private__\",\"captchaId\":\"__private__\"}"`
	#echo ${result}
	token=`echo ${result} | jp data.token | sed 's/^"\(.*\)"$/\1/'`
	return 0

}

function addMenuWithParams()
{
	name=${1}
	hidden=${2}
	parentId=${3}
	component=${4}
	sort=${5}
	result=`curl "http://${server_url}/role/menu/addBaseMenu" -H 'Accept: application/json, text/plain, */*'  -H 'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6' -H 'Content-Type: application/json' \
	  -H "${token}" \
	  --data-raw "{\"ID\":0,\"path\":\"${name}\",\"name\":\"${name}\",\"hidden\":${hidden},\"parentId\":\"${parentId}\",\"component\":\"${component}\",\"meta\":{\"title\":\"${name}\",\"icon\":\"aim\",\"defaultMenu\":false,\"keepAlive\":\"\"},\"sort\":${sort},\"parameters\":[{\"type\":\"params\",\"key\":\"id\",\"value\":\"\"}]}"`
	echo ${result} 
}

function addMenu()
{
	name=${1}
	hidden=${2}
	parentId=${3}
	component=${4}
	sort=${5}
	result=`curl "http://${server_url}/role/menu/addBaseMenu" -H 'Accept: application/json, text/plain, */*'  -H 'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6' -H 'Content-Type: application/json' \
	  -H "${token}" \
	  --data-raw "{\"ID\":0,\"path\":\"${name}\",\"name\":\"${name}\",\"hidden\":${hidden},\"parentId\":\"${parentId}\",\"component\":\"${component}\",\"meta\":{\"title\":\"${name}\",\"icon\":\"aim\",\"defaultMenu\":false,\"keepAlive\":\"\"},\"sort\":${sort}}"`
	echo ${result}
}

#result=`curl "http://${server_url}/role/base/login" \
#  -H 'Accept: application/json, text/plain, */*' \
#  -H 'authorization: ' \
#  -H 'Content-Type: application/json' \
#  --data-raw '{"username":"admin","password":"123456","captcha":"__private__","captchaId":"__private__"}'`
#echo ${result}  

login admin 123456
echo "user token is ${token}"

#addMenuWithParams DiggerOperation true 9 modules/target_schedule/digger/operation.vue 10
#addMenuWithParams LorryOperation true 9 modules/target_schedule/lorry/operation.vue 11
#addMenu diggerlist false 9 modules/target_schedule/digger/view.vue 12
#addMenu lorrylist false 9 modules/target_schedule/lorry/view.vue 13
#addMenu sitelist false 9 modules/target_schedule/unloadsite/view.vue 14
addMenuWithParams AssignPlan true 9 modules/target_schedule/assignplan/view.vue
addMenuWithParams BoomGroup true 9 modules/target_schedule/boomgroup/view.vue
addMenuWithParams BoomPile true 9 modules/target_schedule/boompile/view.vue
addMenuWithParams Location true 9 modules/target_schedule/location/view.vue
addMenuWithParams LorryBinding true 9 modules/target_schedule/lorrydiggerbinding/view.vue
addMenuWithParams Material true 9 modules/target_schedule/material/view.vue
addMenuWithParams Message true 9 modules/target_schedule/message/view.vue
addMenuWithParams MineRequire true 9 modules/target_schedule/minerequire/view.vue
addMenuWithParams MineRequireItem true 9 modules/target_schedule/minerequireitem/view.vue
addMenuWithParams Pad true 9 modules/target_schedule/pad/view.vue
addMenuWithParams Schedule true 9 modules/target_schedule/schedule/view.vue
addMenuWithParams Simcard true 9 modules/target_schedule/simcard/view.vue


